﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using NPOI.HSSF.UserModel;
using NPOI.SS.UserModel;
using NPOI.XSSF.Streaming;
using NPOI.XSSF.UserModel;

namespace Npoi栗子
{
    class Program
    {
        static void Main(string[] args)
        {
            #region 创建Excel

            ////HSSFWorkbook workbook03 = new HSSFWorkbook(); //创建的是03~07版本 后缀为 .xls 
            //XSSFWorkbook workbook = new XSSFWorkbook();  //创建的是07以上版本 后缀为 .xlsx
            //ISheet sheet = workbook.CreateSheet("Sheet1");
            //IRow row = sheet.CreateRow(0);
            //for (int i = 0; i < 5; i++)
            //{
            //    ICell cell = row.CreateCell(i);
            //    cell.SetCellValue("这是第一行第" + i + "个单元格");
            //}

            //using (FileStream stream = new FileStream(@"D:/Npoi_Data.xlsx", FileMode.Create))
            //{
            //    workbook.Write(stream);
            //}

            #endregion

            #region 读取Excel

            //StringBuilder sb = new StringBuilder();
            //using (FileStream fileStream = new FileStream(@"D:/Npoi_Data.xlsx", FileMode.Open))
            //{
            //    XSSFWorkbook workbookNew = new XSSFWorkbook(fileStream);
            //    //循环Sheet
            //    for (int i = 0; i < workbookNew.NumberOfSheets; i++)
            //    {
            //        //获取当前Sheet
            //        ISheet sheetNew = workbookNew.GetSheetAt(i);
            //        //int sheetIndex = workbookNew.GetSheetIndex(i);  //根据Sheet名称获取索引
            //        //ISheet sheetNew= workbookNew.GetSheet("Sheet1"); //根据Sheet名称获取Sheet
            //        for (int j = 0; j < sheetNew.LastRowNum+1; j++)
            //        {
            //            IRow rowNew = sheetNew.GetRow(j); //读取当前行数据
            //            if (rowNew != null)
            //            {
            //                sb.Append("-------------------------------------------\r\n");
            //                for (int k = 0; k < rowNew.LastCellNum; k++)
            //                {
            //                    ICell cellNew = rowNew.GetCell(k);
            //                    if (cellNew != null)
            //                    {
            //                        sb.Append(cellNew.ToString() + "\r");
            //                    }
            //                }
            //                sb.Append("--------------------------------------------------\r\n");
            //            }
            //        }
            //    }
            //}

            //if (!File.Exists("D:/Npoi_Data.txt"))
            //{
            //    File.Create("D:/Npoi_Data.txt");
            //}

            //using (StreamWriter streamWriter = new StreamWriter(new FileStream(@"D:/Npoi_Data.txt", FileMode.Append)))
            //{
            //    streamWriter.Write(sb);
            //    streamWriter.Flush();
            //}


            #endregion

            #region MyRegion
            
            IWorkbook book=new XSSFWorkbook();
            


            #endregion

        }
    }
}
